package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.SysParamsEntity;
import com.csg.ses.service.ses.SysParamsService;
import com.csg.ses.vo.common.IdListVo;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统参数
 * @author wangjun
 * @date 2020/11/16
 */
@RestController
@RequestMapping("/param")
@Api(tags = "系统参数接口")
public class SysParamsController {
    @Autowired
    private SysParamsService sysParamsService;

    /**
     * 系统参数列表
     */
    @ApiOperation(value = "系统参数列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sysParams", value = "系统参数", dataType = "SysParamsEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<SysParamsEntity>> list(SysParamsEntity sysParams, Long current, Long size) {
        return sysParamsService.retrieve(sysParams, current, size);
    }

    @ApiOperation(value = "根据参数类型获取下拉数据")
    @ApiImplicitParam(name = "paramType", value = "参数类型", dataType = "String", required = true)
    @GetMapping("drop-data/{paramType}")
    @LoginToken
    public Result getDropData(@PathVariable String paramType) {
        return sysParamsService.getDropData(paramType);
    }

    /**
     * 删除系统参数
     * @param idList
     * @return
     */
    @ApiOperation(value = "删除系统参数")
    @ApiImplicitParam(name = "idList", value = "系统参数ID数组", dataType = "IdListVo", paramType = "body", required = true)
    @DeleteMapping("/del")
    @LoginToken
    public Result<String> del(@RequestBody IdListVo idList) {
        return sysParamsService.del(idList);
    }

    @ApiOperation(value = "根据id查找系统参数")
    @ApiImplicitParam(name = "id", value = "系统参数id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<SysParamsEntity> getById(@PathVariable String id) {
        return sysParamsService.getById(id);
    }

    /**
     * 保存系统参数
     * @param
     * @return
     */
    @ApiOperation(value = "保存系统参数")
    @ApiImplicitParam(name = "sysParams", value = "系统参数", dataType = "SysParamsEntity", paramType = "body")
    @PostMapping("/save")
    @LoginToken
    public Result<String> save(@RequestBody SysParamsEntity sysParams) {
        boolean result = sysParamsService.save(sysParams);
        if (result) {
            return new Result("保存成功！", ResultStatus.SUCCESS);
        } else {
            return new Result("保存失败！", ResultStatus.BIZ_FAILED);
        }
    }
}